param (
    [string]$User="",
    [string]$User_Pwd="",
    [string]$DatabaseName
)

$DATA_BACKUP_AGENT_HOME = (Get-ChildItem env:DATA_BACKUP_AGENT_HOME).Value
$Location = $DATA_BACKUP_AGENT_HOME + "\DataBackup\ProtectClient\Plugins\GeneralDBPlugin\bin\applications\exchange\ps1_scripts"
Set-Location -Path $Location
[string]$common_file_path = (Get-Location).Path + "\Common.ps1"
[string]$pssession_name = "GetDatabaseGuid"

# 引用Common.ps1
. $common_file_path

# 建立连接
if (!(NewConnection $User $User_Pwd $pssession_name)) {
    return $False
}

if ($null -eq $DatabaseName) {
    ClosePSSession $pssession_name
    return $False
}

$db_detail = Invoke-Command -Session $Session -ScriptBlock {Get-MailboxDatabase -identity $using:DatabaseName | Select-Object Guid}
if (!$?) {
    ClosePSSession $pssession_name
    return $False
}
$Guid = [string]$db_detail.Guid
ClosePSSession $pssession_name
return $Guid